package com.example.blog.controller;

import com.example.blog.model.Comment;
import com.example.blog.model.UserInfo;
import com.example.blog.service.CommentService;
import com.example.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Question CommentController
 * @Date 2023/1/24 15:05
 * @Solution
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    CommentService commentService;
    @Autowired
    UserService userService;
    @RequestMapping("/getcom")
    public List<Comment> getCommentByArtId(int blogId) {
        return commentService.getByArtId(blogId);
    }
    @RequestMapping("/getname")
    public UserInfo getCommentNameByArtId(int uid) {
        return commentService.getCommentNameByUid(uid);
    }
    @RequestMapping("/add")
    public int add(HttpServletRequest request,int blogId,String content) {
        //拿到当前用户信息
        HttpSession session = request.getSession();
        int uid=(int) session.getAttribute("user");
        return commentService.add(uid,blogId,content);
    }
}
